/*   1:    */ package com.atomikos.diagnostics;
/*   2:    */ 
/*   3:    */ import java.io.IOException;
/*   4:    */ import java.text.DateFormat;
/*   5:    */ import java.text.SimpleDateFormat;
/*   6:    */ import java.util.Date;
/*   7:    */ import java.util.logging.FileHandler;
/*   8:    */ import java.util.logging.Formatter;
/*   9:    */ import java.util.logging.Level;
/*  10:    */ import java.util.logging.LogRecord;
/*  11:    */ import java.util.logging.Logger;
/*  12:    */ 
/*  13:    */ public class RotatingFileConsole
/*  14:    */   implements Console
/*  15:    */ {
/*  16: 49 */   private static final Object eolIndicatorParameter = new Object();
/*  17: 51 */   private int level = 1;
/*  18:    */   private Logger logger;
/*  19:    */   private FileHandler handler;
/*  20:    */   
/*  21:    */   public RotatingFileConsole(String fileNamePattern, int limit, int fileCount)
/*  22:    */     throws SecurityException, IOException
/*  23:    */   {
/*  24: 60 */     setLevel(1);
/*  25: 61 */     if (limit >= 0) {
/*  26: 63 */       this.handler = new FileHandler(fileNamePattern, limit, fileCount, true);
/*  27:    */     } else {
/*  28: 68 */       this.handler = new FileHandler(fileNamePattern, true);
/*  29:    */     }
/*  30: 71 */     this.logger = Logger.getLogger("com.atomikos.diagnostics");
/*  31: 72 */     this.logger.addHandler(this.handler);
/*  32: 73 */     this.logger.setLevel(Level.ALL);
/*  33: 74 */     this.logger.setUseParentHandlers(false);
/*  34: 75 */     this.handler.setFormatter(new FileFormatter());
/*  35:    */   }
/*  36:    */   
/*  37:    */   public void println(String string)
/*  38:    */     throws IOException
/*  39:    */   {
/*  40: 85 */     this.logger.log(Level.WARNING, string, eolIndicatorParameter);
/*  41:    */   }
/*  42:    */   
/*  43:    */   public void print(String string)
/*  44:    */     throws IOException
/*  45:    */   {
/*  46: 94 */     Object dummy = null;
/*  47:    */     
/*  48: 96 */     this.logger.log(Level.WARNING, string, dummy);
/*  49:    */   }
/*  50:    */   
/*  51:    */   public void println(String string, int level)
/*  52:    */     throws IOException
/*  53:    */   {
/*  54:105 */     if (getLevel() >= level) {
/*  55:106 */       println(string);
/*  56:    */     }
/*  57:    */   }
/*  58:    */   
/*  59:    */   public void print(String string, int level)
/*  60:    */     throws IOException
/*  61:    */   {
/*  62:116 */     if (getLevel() >= level) {
/*  63:117 */       print(string);
/*  64:    */     }
/*  65:    */   }
/*  66:    */   
/*  67:    */   public void close()
/*  68:    */     throws IOException
/*  69:    */   {
/*  70:127 */     this.handler.close();
/*  71:    */   }
/*  72:    */   
/*  73:    */   public void setLevel(int level)
/*  74:    */   {
/*  75:136 */     this.level = level;
/*  76:    */   }
/*  77:    */   
/*  78:    */   public int getLevel()
/*  79:    */   {
/*  80:142 */     return this.level;
/*  81:    */   }
/*  82:    */   
/*  83:    */   private static class FileFormatter
/*  84:    */     extends Formatter
/*  85:    */   {
/*  86:    */     private DateFormat formatter;
/*  87:    */     
/*  88:    */     FileFormatter()
/*  89:    */     {
/*  90:153 */       this.formatter = new SimpleDateFormat("yy-MM-dd kk:mm:ss,SSS");
/*  91:    */     }
/*  92:    */     
/*  93:    */     public String format(LogRecord record)
/*  94:    */     {
/*  95:161 */       StringBuffer buf = new StringBuffer();
/*  96:    */       
/*  97:163 */       Object[] pars = record.getParameters();
/*  98:164 */       if (pars[0] != null)
/*  99:    */       {
/* 100:165 */         buf.append(this.formatter.format(new Date()));
/* 101:166 */         buf.append(" [" + Thread.currentThread().getName() + "] ");
/* 102:    */       }
/* 103:169 */       buf.append(record.getMessage());
/* 104:170 */       buf.append("\n");
/* 105:    */       
/* 106:172 */       return buf.toString();
/* 107:    */     }
/* 108:    */   }
/* 109:    */ }


/* Location:           C:\myfile\mysoft\apache-maven-3.5.0-bin\apache-maven-3.5.0\myrep\com\atomikos\atomikos-util\3.7.0\atomikos-util-3.7.0.jar
 * Qualified Name:     com.atomikos.diagnostics.RotatingFileConsole
 * JD-Core Version:    0.7.0.1
 */